const express = require("express")
const mongoose = require("mongoose")

const app = express()
app.use(express.urlencoded({ extended: true }))
app.use(express.json())
const router = require("./routes")
app.use("/api", router)

mongoose
  .connect("mongodb://localhost/jwt", {
    useNewUrlParser: true,
    useUnifiedTopology: true,
  })
  .then(
    () => {
      console.log("数据库连接成功")
      app.listen("4000", function () {
        console.log("http://localhost:4000/api")
      })
    },
    (err) => {
      console.log("数据库连接失败", err)
    }
  )
